home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / hash.com / HASHTABL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-09-26  |  2.0 KB  |  74 lines

  1. Unit HashTabl;
  2. {$R-,S-,V-}
  3.  
  4. { This Unit demonstrates the correct method of implementation for }
  5. { descendent Hash Tables, Using the Generic Hash Table defined in }
  6. { Unit GenTable.                                                  }
  7.  
  8. INTERFACE
  9.  
  10. Uses GenTable;
  11.  
  12. Type
  13.   DataRec = Record
  14.               Symb : String;  {Symbol string: assumed all uppercase}
  15.               Addr : Word;    {Symbol Address where found in source}
  16.               Line : Word;    {Line Number where found in source   }
  17.             End;
  18.  
  19.   SymbolTable = Object (HTable)
  20.  
  21.                 Data : DataRec;
  22.  
  23.                 Procedure Create;
  24.                 Procedure Enter (TheKey : String; D : DataRec;
  25.                                       Var Duplicate : Boolean);
  26.                 Procedure Retrieve (TheKey : String; Var Found : Boolean;
  27.                                      Var D : DataRec);
  28. {
  29.   (* HTable methods which apply *)
  30.  
  31.                 Procedure Destroy;
  32. }
  33.               End;
  34.  
  35. IMPLEMENTATION
  36.  
  37. Procedure SymbolTable.Create;  { Instantiates a Generic HashTable }
  38.                                { Using DataRec as the stored Data }
  39. Begin
  40.   HTable.Create (SizeOf(DataRec))
  41. End;
  42.  
  43. Procedure SymbolTable.Enter (TheKey : String; D : DataRec;
  44.                                   Var Duplicate : Boolean);
  45.  
  46. { Enters a DataRec into the HashTable. Use D.Symb as TheKey}
  47.  
  48. Var
  49.   Temp : EntryRec;
  50. Begin
  51.   Temp.Create ('');
  52.   Temp.Init (SizeOf (DataRec));
  53.   Temp.Set_Data (D,SizeOf (D));
  54.   Temp.Key := TheKey;
  55.   HTable.Enter (Temp,Duplicate);
  56.   Temp.Destroy
  57. End;
  58.  
  59. Procedure SymbolTable.Retrieve (TheKey : String; Var Found : Boolean;
  60.                                  Var D : DataRec);
  61.  
  62. { Retrieves a DataRec from the HashTable (If Found). If Not Found, }
  63. { D will be undefined (or will still contain old Data).            }
  64.  
  65. Var
  66.   Temp : EntryRec;
  67. Begin
  68.   HTable.Retrieve (TheKey,Found,Temp);
  69.   If Found Then
  70.     Temp.Get_Data (D,SizeOf (D))
  71. End;
  72.  
  73. BEGIN
  74. END.